<!--新入检查-->

<template>
  <div class="app-container">
    <!-- 查询条件开始 -->
    <el-card style="margin-bottom:3px">
      <el-form ref="queryForm" :model="queryParams" label-width="68px">
        <el-form-item label="检查项目" prop="checkItemIds">
          <el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange">全选</el-checkbox>
          <div style="margin: 15px 0;" />
          <el-checkbox-group v-model="queryParams.checkItemIds" @change="handleCheckedItemChange">
            <el-checkbox
                v-for="d in checkItemOptions"
                :key="d.checkItemId"
                :label="d.checkItemId"
                :value="d.checkItemId"
            >{{ d.checkItemName}}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="挂号单号" prop="regId">
          <el-input
              v-model="queryParams.regId"
              placeholder="请输入挂号单号"
              clearable
              size="small"
              style="width:380px"
          />
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button type="primary" icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <!-- 查询条件结束 -->

    <!-- 数据表格开始 -->
    <el-card style="margin-bottom:3px">
      <el-table
          ref="refTable"
          v-loading="loading"
          border
          highlight-current-row
          :data="careOrderItems"
          @current-change="handleCurrentChange"
      >
        <el-table-column label="序号" align="center" type="index" width="50" />
        <el-table-column label="详情ID" align="center" width="300" prop="itemId" />
        <el-table-column label="项目名称" align="center" prop="itemName" />
        <el-table-column label="数量" align="center" prop="num" />
        <el-table-column label="单价(元)" align="center" prop="price" />
        <el-table-column label="金额(元)" align="center" prop="amount" />
        <el-table-column label="备注" align="center" prop="remark" />
        <el-table-column label="状态" align="center" min-width="120" fixed="right" prop="status" :formatter="statusFormat" />
      </el-table>
    </el-card>
    <!-- 数据表格结束 -->


    <!-- 开始检查开始 -->
    <el-card style="margin-bottom:3px">
      <div v-if="showBottom" v-loading="bottomLoading">
        <el-form label-position="left" label-width="120px" inline class="demo-table-expand">
          <el-form-item label="挂号单号:">
            <span>{{ careHistoryObj}}</span>
          </el-form-item>
          <el-form-item label="患者姓名:">
            <span>{{ careOrderObj}}</span>
          </el-form-item>
          <el-form-item label="检查项目:">
            <span>{{ careOrderItemObj.name }}</span>
          </el-form-item>
          <el-form-item label="检查备注:">
            <span>{{ careOrderItemObj.remark }}</span>
          </el-form-item>
        </el-form>
        <div>
          <el-button type="primary" style="width:100%" icon="el-icon-plus" @click="handleStartCheck">开始检查</el-button>
        </div>
      </div>
      <div v-else style="text-align:center">
        暂无数据
      </div>
    </el-card>
    <!-- 开始检查结束 -->

  </div>
</template>
<script>
export default {
  data(){
    return{
      // 遮罩
      loading: false,
      // 检查项目数据
      checkItemOptions: [],
      // 查询参数
      queryParams: {
        checkItemIds: []
      },
      // 是否全选
      checkAll: true,
      // 是否为半选状态
      isIndeterminate: false,
      // 处方详情的表格数据
      careOrderItems: [],
      // 当前选中的行
      currentRow: undefined,
      // 处方详情的状态字典
      statusOptions: [],
      //单号
      regIdOptions:[],
      //名字
      nameOptions:[],
      // 是否显示开始检查的card
      showBottom: false,
      // 下面的开始card的遮罩
      bottomLoading: false,
      // 详情对象
      careOrderItemObj: {},
      // 处方对象
      careOrderObj: {},
      // 病历对象
      careHistoryObj: {},
      //所有数据集合
      quaryOptions:[]
    }
  },
  created() {
    //所有可用的检查项目
    this.$http.get("/checkItemjsh/queryAll").then(res=>{
      this.checkItemOptions = res.data.data
      // console.log("checkItemOptions"+JSON.stringify(this.checkItemOptions)+"======================")
      this.queryParams.checkItemIds = this.checkItemOptions.map(item => item.checkItemId)
      // console.log("queryParams.checkItemIds"+JSON.stringify(this.queryParams.checkItemIds)+"======================")
      // this.loadTable()
    })

  },
  methods:{
// 全选
    handleCheckAllChange(val) {
      this.queryParams.checkItemIds = val ? this.checkItemOptions.map(item => item.checkItemId) : []
      this.isIndeterminate = false
    },
    // 选择某一个项目
    handleCheckedItemChange(value) {
      const checkedCount = value.length
      this.checkAll = checkedCount === this.checkItemOptions.length
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.checkItemOptions.length
    },
    // 根据条件查询已经支付的查询项目
    loadTable(){
      //this.queryParams{"checkItemIds":[1,2,3,4,11,16],"regId":"GH1834503734795235328"}===========
      //console.log("this.queryParams"+JSON.stringify(this.queryParams)+"===========")
      this.$http.post("/careOrderItemCheck/queryByParams",this.queryParams).then(res=>{
        console.log("res.data:"+JSON.stringify(res.data)+"!!!!!!!!!!!!")
        this.careOrderItems = res.data.data.data;
      })
    },

    // 状态字典翻译
    statusFormat(row){
      let msg = '未知'
      if (row.status === row.dictValue){
        msg = row.dictLabel
      }
      return msg
    },


    // 选中某一行之后
    handleCurrentChange(val) {
      this.currentRow = val
      if (val !== null) {
        this.bottomLoading = true
        //console.log("val:"+JSON.stringify(this.currentRow.itemId)+"======================")
        this.$http.get("/careOrderItemCheck/queryByItemId?itemId="+this.currentRow.itemId).then(res=>{
          // console.log(res.data)
          // 所有对象传入
          this.quaryOptions=res.data.data
          //quaryOptions:{"careHistoryObj":"GH1834503734795235328","careOrderObj":"唐太宗","careItemObj":{"name":"血常规","remark":"按要求检查"}}======================
          //console.log("res.data:"+JSON.stringify(this.quaryOptions)+"======================")
          this.careOrderItemObj = res.data.data.careItemObj
          this.careOrderObj = res.data.data.careOrderObj
          this.careHistoryObj = res.data.data.careHistoryObj
          this.showBottom = true
          this.bottomLoading = false
        })
      }
    },

    // 查询
    handleQuery() {
      this.loadTable()
      this.showBottom = false
    },
    // 重置
    resetQuery() {
      //this.resetForm('queryForm')
      // this.showBottom = false
      // this.queryParams.checkItemIds = this.checkItemOptions.map(item => item.checkItemId)
      this.checkAll = false
      this.queryParams.regId = undefined
      this.queryParams.checkItemIds = []
      this.loadTable()
    },
    // 开始检查
    handleStartCheck(row) {
      this.$confirm('是否确定开始检查?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        //quaryOptions:{"careHistoryObj":"GH1834503734795235328","careOrderObj":"唐太宗","careItemObj":{"name":"血常规","remark":"按要求检查"}}
        //console.log(JSON.stringify(this.quaryOptions)+"================")
        this.$http.post("/checkResultCheck/startChecking",this.quaryOptions).then(res=>{
          this.loadTable()
          this.showBottom = false
        })
      })
    },
  }
}
</script>

<style scoped>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>